package cn.bluethink.zentao.controller;

 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.bluethink.zentao.filter.ZentaoFilter;
import cn.bluethink.zentao.model.ZtProjectStatistics;
import cn.bluethink.zentao.model.ZtStatistics;
import cn.bluethink.zentao.model.ZtTask;
import cn.bluethink.zentao.model.ZtUser;
import cn.bluethink.zentao.page.PageInfo;
import cn.bluethink.zentao.result.ResponseMessage;
import cn.bluethink.zentao.result.ResponseResult;
import cn.bluethink.zentao.service.ZenTaoService;

/**
 * 禅道服务controller层
 * 
 * @title 苏州中科蓝迪公司所有(c)2016-2021
 * @version 0.1.0
 * @describe 
 * @author fanBl
 * @date  2018年12月12日
 */
@CrossOrigin
@RestController
@RequestMapping("/v1.0/zentao")
public class ZentaoController {

	@Autowired
	private ZenTaoService zantaoService;

	/**
	 * 根据条件获取禅道用户列表
	 * 
	 * @param filter
	 * @return
	 * @throws Exception
	 */
	@PostMapping("/ztusers")
	public ResponseResult<PageInfo<ZtUser>> ztusers(@RequestBody ZentaoFilter filter) throws Exception {
		
		
		return new ResponseResult<>(ResponseMessage.OK, zantaoService.ztusers(filter));
	}

	/**
	 * 根据条件获取禅道任务列表
	 * 
	 * @param filter
	 * @return
	 * @throws Exception
	 */
	@PostMapping("/zttasks")
	public ResponseResult<PageInfo<ZtTask>> zttasks(@RequestBody ZentaoFilter filter) throws Exception {
		return new ResponseResult<>(ResponseMessage.OK, zantaoService.zttasks(filter));
	}

	/**
	 * 获取禅道项目列表，以及其项目成员，完成任务，延误任务
	 * 
	 * @return
	 * @throws Exception
	 */
	@PostMapping("/ztprojects")
	public ResponseResult<PageInfo<ZtProjectStatistics>> ztprojects(@RequestBody ZentaoFilter filter) throws Exception {
		return new ResponseResult<>(ResponseMessage.OK, zantaoService.ztprojects(filter));
	}

	/**
	 * @api {POST} /v1.0/zantao/statistics 禅道统计
	 * @apiGroup Users
	 * @apiVersion 0.0.1
	 * @apiDescription 用于禅道统计
	 * @apiParam {String} id 项目id
	 * @apiParam {String} etime 结束时间
	 * @apiParam {String} btime 开始时间
	 * @apiParam {String} douId 任务执行者id
	 */
	@PostMapping("/statistics")
	public ResponseResult<PageInfo<ZtStatistics>> statistics(@RequestBody ZentaoFilter filter) throws Exception {
		// 2、获取filter中的btime和etime，如果为空，默认为当前日期所在周，根据时间段获取周任务进展情况
		// 根据 douid（任务执行者id） 查询该用户 周任务进展情况
		PageInfo<ZtStatistics> zanTaoStatistics = zantaoService.zanTaoStatistics(filter);
		 
		return new ResponseResult<>(ResponseMessage.OK, zanTaoStatistics);
	}

	/**
	 * @api {POST} /v1.0/zantao/delaytasks 禅道备注
	 * @apiGroup Users
	 * @apiVersion 0.0.1
	 * @apiDescription 用于禅道延误+暂停任务 的
	 * @apiParam {String} id 项目id
	 * @apiParam {String} etime 结束时间
	 * @apiParam {String} btime 开始时间
	 * @apiParam {String} douId 任务执行者id
	 * 
	 */
	@PostMapping("/delaytasks")
	public ResponseResult<PageInfo<ZtTask>> delaytasks(@RequestBody ZentaoFilter filter) throws Exception {
		// 2、获取filter中的btime和etime，如果为空，默认为当前日期所在周，根据时间段获取【延误+暂停】任务列表
		PageInfo<ZtTask> delaytasks = zantaoService.delaytasks(filter);
		return new ResponseResult<>(ResponseMessage.OK, delaytasks);
	}
    
}
